<template>
  <div id="palletbindding" v-loading="loading">
    <v-tableTitle :btnConfig="btnConfig" :tableSelectData="tableSelectData" :title="$t('ex.bindtp')" @unbindding="unbindding"></v-tableTitle>
    <v-table :pageSize="pageSize" :page="page" :tableConfig="tableConfig" :tableData="tableData" :total="total" @findData="getTableData" @getTableData="getTableData" @searhData="searhData"
      @selectData="selectData" @setdialog="setdialog" @upData="getTableData" ref="table"></v-table>
  </div>
</template>

<script type="text/ecmascript-6">
import tableTitle from 'commons/TableTitle'
import table from 'commons/Table'
import baseMixin from '@/mixins/BaseMixin'
import config from './Config'
import bus from '../../../../bus/bus'

export default {
  name: 'palletbindding',
  mixins: [baseMixin, config],
  data() {
    return {
      loading: false,
      tableConfig: [
        {
          label: this.$t('out.palletkey'),
          prop: 'palletkey',
          input: 'input'
        },
        {
          label: this.$t('in.standardlpn'),
          prop: 'lpn',
          input: 'input'
        },
        {
          label: this.$t('outbound.fromloc'),
          prop: 'fromloc',
          input: 'input'
        },
        {
          label: this.$t('ex.middloc'),
          prop: 'middloc',
          input: 'input'
        },
        {
          label: this.$t('config.toLoc'),
          prop: 'toloc',
          input: 'input'
        },
        {
          label: this.$t('ex.palletstatus'),
          prop: 'palletstatus',
          input: 'select',
          options: this.getOptions('codelkup/RTXPALSTATUS')
        },
        {
          label: this.$t('ex.pallettype'),
          prop: 'pallettype',
          input: 'select',
          options: this.getOptions('codelkup/RTXPALTYPE')
        }
      ],
      tableData: [],
      page: 1,
      pageSize: 10,
      total: 0,
      tableSelectData: [],
      tableSearhData: {}
    }
  },
  computed: {
    btnConfig() {
      return [
        {
          label: this.$t('ex.unbindding'),
          certigier: !this.btnPermNameList.includes('WM06020601'),
          disabled: true,
          invalid: 'unbindding'
        }
      ]
    }
  },
  created() {},
  methods: {
    unbindding(data) {
      data.forEach(async (item, index) => {
        try {
          let res = await this.$api.get(
            `/palletbindding/unbindding/${item.palletkey}`
          )
          
            this.$message.success(res.returnMgr)
            this.getTableData(1, {})
            this.$refs.table.delSelectData(item, index)
          
        } catch (e) {
          this.$message.error(e)
        }
      })
    },
    //选中的内容
    selectData(data) {
      this.tableSelectData = data
    },
    async getTableData(page, data) {
      try {
        this.loading = true
        let res = await this.$api.post(`/palletbinddingOfDark/${page}`, data)
        
          this.tableData = res.page.list
          this.page = res.page.curpage
          this.pageSize = res.page.pageSize
          this.total = res.page.total
        
      } catch (e) {
        this.$message.error(e)
      } finally {
        this.loading = false
      }
    },
    //搜索的值
    searhData(data, up) {
      if (!up) {
        this.tableSearhData = data
      } else {
        this.tableSearhData = data
        this.getTableData(1, this.tableSearhData)
      }
    },
    //设置弹框
    setdialog(data) {
      this.$router.push({ name: 'palletbinddingDeawer', query: data })
    }
  },
  mounted() {
    this.getTableData(1, {})
  },
  components: {
    'v-tableTitle': tableTitle,
    'v-table': table
  }
}
</script>

<style scoped>
#palletbindding {
  width: 100%;
  height: 99%;
  padding-top: 6px;
}
</style>
